package com.miniapp.web.controller.paicfti;

import com.alibaba.fastjson.JSONObject;

import com.miniapp.common.annotation.Anonymous;
import com.miniapp.common.core.controller.BaseController;
import com.miniapp.common.core.domain.AjaxResult;
import com.miniapp.common.core.domain.entity.miniapp.MiniAppUser;
import com.miniapp.common.core.domain.model.LoginUser;
import com.miniapp.common.core.page.TableDataInfo;
import com.miniapp.core.domain.PaicPolicyDetailsResult;
import com.miniapp.core.domain.PaicPolicyParam;
import com.miniapp.core.domain.PaicPolicyResult;
import com.miniapp.core.domain.paicfti.*;
import com.miniapp.core.service.IPaicFtiService;
import com.miniapp.core.service.impl.PaicFtiServiceImpl;
import com.miniapp.core.utils.PaicFtiPolicyFileDownload;
import io.swagger.models.auth.In;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 平安货运险投保
 */
@RestController
@RequestMapping("/paicFti")
public class PaicFtiController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(PaicFtiController.class);

    @Autowired
    private IPaicFtiService paicFtiService;

    @Autowired
    private PaicFtiPolicyFileDownload paicFtiPolicyFileDownload;

    /**
     * 平安货运险投保
     * @return
     */
//    @Anonymous
    @ResponseBody
    @PostMapping("/insure")
    public AjaxResult insure(@RequestBody PaicFtiInsureParam paicFtiInsureParam){
//        MiniAppUser miniAppUser = new MiniAppUser();
//        miniAppUser.setPurePhoneNumber("13381227115");
//        miniAppUser.setOpenId("o60_K66veBb-HpcfXCOVwS7UofQI");
//        LoginUser loginUser = new LoginUser(miniAppUser);

        LoginUser loginUser = getLoginUser();
        paicFtiInsureParam.setLoginUser(loginUser);
        AjaxResult insure = paicFtiService.insure(paicFtiInsureParam);
        return insure;
    }


    @Anonymous
    @ResponseBody
    @PostMapping("/downloadPolicy")
    public AjaxResult insure(String policyNo){
        paicFtiPolicyFileDownload.policyFileDownload(policyNo);

        return AjaxResult.success();
    }






    /**
     * 保单列表
     * @param paicPolicyParam
     * @return
     */
    @ResponseBody
    @GetMapping("/policyList")
    public TableDataInfo policyList(PaicPolicyParam paicPolicyParam){
        startPage();
        List<PaicPolicyResult> paicPolicyResults = paicFtiService.policyList(paicPolicyParam);
        return getDataTable(paicPolicyResults);
    }

    /**
     * 查询保单详情
     * @param policyId
     * @return
     */
    @ResponseBody
    @GetMapping("/policyDetails")
    public AjaxResult policyDetails(Integer policyId){
        PaicPolicyDetailsResult paicPolicyDetailsResult = paicFtiService.policyDetails(policyId);
        return AjaxResult.success(paicPolicyDetailsResult);
    }


    /**
     * 平安货运险保费计算
     * @param premiumCalculationParam
     * @return
     */
    @ResponseBody
    @PostMapping("/premiumCalculation")
    public AjaxResult premiumCalculation(@RequestBody PremiumCalculationParam premiumCalculationParam){
        AjaxResult ajaxResult = paicFtiService.premiumCalculation(premiumCalculationParam);
        return ajaxResult;
    }









    public static void main(String[] args) {
        PaicFtiInsureParam paicFtiInsureParam = new PaicFtiInsureParam();
        //客户信息
        PaicFtiInsurantParam paicFtiInsurant = new PaicFtiInsurantParam();
        paicFtiInsurant.setCustomerType("001");
        paicFtiInsurant.setCustomerName("无线天利");
        paicFtiInsurant.setCustomerIdNum("130682199510020077");
        paicFtiInsurant.setContactPerson("尹卫东");
        paicFtiInsurant.setContactPonhe("13381227115");
        paicFtiInsurant.setContactAddress("河北省定州市");
        paicFtiInsureParam.setPaicFtiInsurant(paicFtiInsurant);
        paicFtiInsureParam.setProductType("TC001");

        //货物信息
        PaicFtiCargo paicFtiCargo = new PaicFtiCargo();
        paicFtiCargo.setCargoType("03");
        paicFtiCargo.setPackingType("06");
        paicFtiCargo.setCargoMessage("普通灌灌灌灌货物");
        paicFtiInsureParam.setPaicFtiCargo(paicFtiCargo);

        //运输信息
        PaicFtiTransport paicFtiTransport = new PaicFtiTransport();
        paicFtiTransport.setInvoiceNumber("123456");
        paicFtiTransport.setWaybillNumber("654321");
        paicFtiTransport.setLicensePlateNumber("冀FG6932");
        paicFtiTransport.setPlaceOfDispatch("河北省定州市");
        paicFtiTransport.setDestination("河北省邢台市");
        paicFtiTransport.setShippingTime("2024-11-05 16");
        paicFtiInsureParam.setPaicFtiTransport(paicFtiTransport);

        PaicFtiInsurance paicFtiInsurance = new PaicFtiInsurance();
        paicFtiInsurance.setInsuranceAmount(1000*100);
        paicFtiInsurance.setPremium(1*100);
        paicFtiInsureParam.setPaicFtiInsurance(paicFtiInsurance);

        String s = JSONObject.toJSONString(paicFtiInsureParam);
        System.out.println(s);
    }





}
